const cheerio = require('cheerio');

function parseNewsList(html) {
  const $ = cheerio.load(html);
  const newsItems = [];
  
  $('.news-item').each((index, element) => {
    const $element = $(element);
    
    const title = $element.find('.title').text().trim();
    const summary = $element.find('.summary').text().trim();
    const url = $element.find('a').attr('href');
    const imageUrl = $element.find('img').attr('src');
    const pubDate = $element.find('.date').text().trim();
    
    if (title && url) {
      newsItems.push({
        title,
        summary,
        url,
        imageUrl,
        pubDate,
        source: 'qq-news',
        createdAt: new Date()
      });
    }
  });
  
  return newsItems;
}

function parseArticle(html) {
  const $ = cheerio.load(html);
  
  const content = $('.article-content').html() || '';
  const author = $('.article-author').text().trim() || '';
  
  return {
    content,
    author
  };
}

module.exports = {
  parseNewsList,
  parseArticle
};  